package pikes.peak;

import java.util.HashMap;
import java.util.Map;

import org.junit.Test;
import pikes.html.xhtml.Division;
import pikes.html.xhtml.Flow;
import pikes.html.xhtml.text.Paragraph;
import pikes.peak.Component;
import pikes.peak.Composite;
import pikes.peak.VisibilityCondition;
import pikes.peak.test.AssertHtml;
import pikes.peak.test.PikesPeakComponentTestCase;

import org.springframework.web.servlet.support.RequestContext;

public class CompositeTestCase extends PikesPeakComponentTestCase {

	@Test
	public void testSetClazz() throws Exception {
		Composite composite = new Composite();

		Division expected = new Division();
		Flow actual = composite.createHtml(new HashMap(), pikesPeakRequest.getRequestContext());
		AssertHtml.assertEquals(expected, actual);
	}

	@Test
	public void testAdd() throws Exception {
		Composite composite = new Composite();

		composite.add(new Component() {

			public Flow createHtml(Map model, RequestContext requestContext) throws Exception {
				return new Paragraph();
			}

		});

		Division expected = new Division();
		expected.add(new Paragraph());
		Flow actual = composite.createHtml(new HashMap(), pikesPeakRequest.getRequestContext());
		AssertHtml.assertEquals(expected, actual);
	}

	@Test
	public void testAddWithCondition() throws Exception {
		Composite composite = new Composite();

		composite.add(new Component() {

			public Flow createHtml(Map model, RequestContext requestContext) throws Exception {
				return new Paragraph();
			}

		}, new VisibilityCondition() {

			public boolean isTrue(Map model, RequestContext requestContext) throws Exception {
				return false;
			}

		});

		Division expected = new Division();
		Flow actual = composite.createHtml(new HashMap(), pikesPeakRequest.getRequestContext());
		AssertHtml.assertEquals(expected, actual);
	}

}
